package com.crm.CLdriving.controller;

import java.util.List;

import javax.validation.Valid;

import com.crm.CLdriving.common.PageResponse;
import com.crm.CLdriving.dto.PageReq.PageNumber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.crm.CLdriving.common.BaseResponse;
import com.crm.CLdriving.dto.IdReqDto;
import com.crm.CLdriving.dto.req.ExaminInputReqDto;
import com.crm.CLdriving.dto.req.ExaminInsertReqDto;
import com.crm.CLdriving.dto.req.ExaminUpdateReqDto;
import com.crm.CLdriving.enu.ResponseEnum;
import com.crm.CLdriving.po.ExaminPO;
import com.crm.CLdriving.service.ExaminService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;

@Controller
@Api(tags="考试成绩信息管理")
@Log4j2
@RequestMapping("examin")
public class ExaminController {

	@Autowired
	private ExaminService examinService;
	
	@PostMapping("select")
	@ApiOperation("查询  (所有学员) 考试成绩信息接口")
	@ResponseBody
	public PageResponse<List<ExaminPO>> selectall(@RequestBody PageNumber pageNumber){
		return examinService.selectAll(pageNumber);
	}
	
	
	@PostMapping("selectInput")
	@ResponseBody
	@ApiOperation("筛选查询考试信息接口")
	public BaseResponse<List<ExaminPO>> SelectInput(@RequestBody @Valid ExaminInputReqDto examinInputReqDto){
		log.info("筛选框查询请求参数："+JSON.toJSONString(examinInputReqDto));
		if ((examinInputReqDto.getIdentity()==null || examinInputReqDto.getIdentity()=="") &&
				(examinInputReqDto.getName()==null || examinInputReqDto.getName()=="")) {
			return BaseResponse.message(ResponseEnum.MYSXTJ);
		}
		return examinService.selectInput(examinInputReqDto);		
	}
	
	
	@PostMapping("deleteById")
	@ResponseBody
	@ApiOperation("根据id删除考试信息")
	public BaseResponse<?> DeleteById(@RequestBody @Valid IdReqDto idReqDto){
		log.info("根据id删除考试信息"+JSON.toJSONString(idReqDto));
		return examinService.deleteById(idReqDto);
		
	}
	
	//???????不需要？？？？？
	@PostMapping("insert")
	@ResponseBody
	@ApiOperation("录入考试成绩信息接口")
	public BaseResponse<?> Insert(@Valid @RequestBody ExaminInsertReqDto examinInsertReqDto){
		log.info(""+JSON.toJSONString(examinInsertReqDto));
		return examinService.insert(examinInsertReqDto);
	}
	
	//????????不需要？？？？？
	@PostMapping("updateById")
	@ResponseBody
	@ApiOperation("更新考试成绩信息接口")
	public BaseResponse<?> Update(@Valid @RequestBody ExaminUpdateReqDto examinUpdateReqDto){
		log.info(""+JSON.toJSONString(examinUpdateReqDto));
		return examinService.update(examinUpdateReqDto);
	}
}
